﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SourFruit.level.obj;
using System.Diagnostics;

namespace SourFruit.level
{
    public class Level
    {
        private Dictionary<int, Platform> platforms;
        private Dictionary<int, Collectable> collectables;
        private Goal goal;
        private int id;

        /// <summary>
        /// Creates an empty level.
        /// </summary>
        /// <param name="_length">The lenght of the level. The exact value is the goal line.</param>
        public Level(Goal _goal)
        {
            _goal.ID = 0;
            this.goal = _goal;
            this.platforms = new Dictionary<int, Platform>();
            this.collectables = new Dictionary<int, Collectable>();
            id = 1;
        }

        public Dictionary<int, Collectable> Collectables { get { return this.collectables; } set { this.collectables = value; } }
        public Dictionary<int, Platform> Platforms { get { return this.platforms; } set { this.platforms = value; } }
        public Goal Goal { get { return this.goal; } set { this.goal = value; } }

        /// <summary>
        /// Adds a single platform to the level.
        /// </summary>
        /// <param name="platform">The platform to be added.</param>
        public void addPlatform(Platform platform)
        {
            platform.ID = id;
            this.platforms.Add(id, platform);
            id++;
        }

        /// <summary>
        /// Adds a single collectable to the level.
        /// </summary>
        /// <param name="collectable">The collectable to be added.</param>
        public void addCollectable(Collectable collectable)
        {
            collectable.ID = id;
            this.collectables.Add(id, collectable);
            id++;
        }

        public void removeCollectable(int _id, int value)
        {
            this.collectables.Remove(_id);
        }

        /// <summary>
        /// Moves all the level objects, creating the scrolling effect.
        /// </summary>
        /// <param name="distance">The distance how far the objects will be moved.</param>
        public void MoveAllObjects(int distance)
        {
            foreach (var p in platforms){
                p.Value.PosX -= distance;
                p.Value.CreateEventPositionChanged();
            }
            foreach (var c in collectables)
            {
                c.Value.PosX -= distance;
                c.Value.CreateEventPositionChanged();
            }
            this.goal.PosX -= distance;
            this.goal.CreateEventPositionChanged();
        }

        //public void createEventCollected(int id)
        //{
        //    if (collected != null)
        //        (this, posX, posY, id);
        //}
    }
}
